package com.aar.rest.graphics;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Menu extends JMenuBar{
        private static final long serialVersionUID = 1L;
        private JMenu menuFile;
        private JMenu menuChild;
        private JMenu menuGift;
        private JMenu menuHelp;
        private Window window;
        
        public Menu(Window window){
                super();
                this.window = window;
                menuFile = CreateMenuFile();
                menuChild = CreateMenuChild();
                menuGift = CreateMenuGift();
                menuHelp = CreateMenuHelp();
                this.add(menuFile);
                this.add(menuChild);
                this.add(menuGift);
                this.add(menuHelp);
        }
        
        private JMenu CreateMenuFile() {
            JMenu menuFile = new JMenu();

            menuFile.setText("Fichier");
            JMenuItem newView = CreateNewView();
            JMenuItem exit = CreateButtonExit();
            menuFile.add(newView);
            menuFile.addSeparator();
            menuFile.add(exit);

            return menuFile;
        }
        
        private JMenu CreateMenuChild() {
            JMenu menuChild = new JMenu();
            menuChild.setText("Gestion-Enfants");
            JMenuItem showChildren = CreateButtonShowChild();
            JMenuItem searchChild = CreateButtonSearchChild();            
            menuChild.add(showChildren);
            menuChild.add(searchChild);
            return menuChild;
        }
	
	    private JMenu CreateMenuGift() {
	            JMenu menuGift = new JMenu();
	            menuGift.setText("Gestion-Cadeaux");
	            JMenuItem showGifts = CreateButtonShowGifts();
	            JMenuItem searchGift = CreateButtonSearchGift();	            
	            menuGift.add(showGifts);
	            menuGift.add(searchGift);
	            return menuGift;
	    }
	        
        private JMenu CreateMenuHelp() {
                JMenu menuHelp = new JMenu();
                menuHelp.setText("Aide");
                JMenuItem helpContent = CreateButtonHelpContent();
                JMenuItem about = CreateButtonAbout();
                menuHelp.add(helpContent);
                menuHelp.add(about);
                return menuHelp;
        }
        
        private JMenuItem CreateButtonShowChild(){
                JMenuItem showChildren = new JMenuItem();
                showChildren.setText("Afficher les enfants");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                window.getCore().showChildren();                 
                        }
                };
                showChildren.addActionListener(action);
                showChildren.setEnabled(true);
                return showChildren;
        }
       
        private JMenuItem CreateButtonSearchChild(){
                JMenuItem searchChildren= new JMenuItem();
                searchChildren.setText("Chercher un enfant");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                window.getCore().searchChildren();               
                        }
                };
                searchChildren.addActionListener(action);
                searchChildren.setEnabled(true);

                return searchChildren;
        }
       
        private JMenuItem CreateButtonShowGifts(){
                JMenuItem showChildren = new JMenuItem();
                showChildren.setText("Afficher les cadeaux");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                window.getCore().showGifts();                 
                        }
                };
                showChildren.addActionListener(action);
                showChildren.setEnabled(true);
                return showChildren;
        }
        
        private JMenuItem CreateButtonSearchGift() {
            JMenuItem searchChildren= new JMenuItem();
            searchChildren.setText("Chercher un cadeau");
            java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                            window.getCore().searchGift();               
                    }
            };
            searchChildren.addActionListener(action);
            searchChildren.setEnabled(true);
            return searchChildren;
        }

        private JMenuItem CreateNewView(){
            JMenuItem exit = new JMenuItem();
            exit.setText("Nouvelle Fenètre");
            java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                    	new Window();
                    }
            };
            exit.addActionListener(action);
            exit.setEnabled(true);
            return exit;
        }
        private JMenuItem CreateButtonExit(){
                JMenuItem exit = new JMenuItem();
                exit.setText("Quitter");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                System.exit(0);
                        }
                };
                exit.addActionListener(action);
                exit.setEnabled(true);
                return exit;
        }
        
        private JMenuItem CreateButtonAbout() {
                JMenuItem exit = new JMenuItem();
                exit.setText("Contact");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                window.getCore().about();
                        }
                };
                exit.addActionListener(action);
                exit.setEnabled(true);
                return exit;
        }

        private JMenuItem CreateButtonHelpContent() {
                JMenuItem exit = new JMenuItem();
                exit.setText("Aide");
                java.awt.event.ActionListener action = new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                                window.getCore().helpContent();
                        }
                };
                exit.addActionListener(action);
                exit.setEnabled(true);
                return exit;
        }
}